{% extends "projects/project_edit_base.html" %}

{% load i18n %}
{% load static %}

{% block title %}{% trans "Redirects" %}{% endblock %}

{% block extra_links %}
  <link rel="stylesheet" type="text/css" href="{% static "projects/css/admin.css" %}" />
{% endblock %}

{% block project-redirects-active %}active{% endblock %}
{% block project_edit_content_header %}{% trans "Redirects" %}{% endblock %}

{% block project_edit_content %}
  <p class="help_text">
    {% blocktrans trimmed with docs_url='https://docs.readthedocs.io/page/user-defined-redirects.html' %}
        Add redirects for your project. This allows you to fix links to old pages that are 404ing. <a href="{{ docs_url }}">Learn more</a>.
    {% endblocktrans %}
  </p>

  <div class="button-bar">
    <ul>
      <li>
        <a class="button"
           href="{% url 'projects_redirects_create' project_slug=project.slug %}">
          {% trans "Add Redirect" %}
        </a>
      </li>
    </ul>
  </div>

  <div class="module">
    <div class="module-list automation-rules">
      <div class="module-list-wrapper">
        <ul>
          {% for redirect in redirects %}
            <li class="module-item">
              <div>
                {{ redirect.get_redirect_type_display }}
              </div>
              {% if redirect.get_from_to_url_display %}
                <div>
                  {{ redirect.get_from_to_url_display }}
                </div>
              {% endif %}
              <ul class="module-item-menu">
                {% if not forloop.first %}
                  <li class="automation-rule">
                    <form method="post" action="{% url 'projects_redirects_insert' project_slug=project.slug redirect_pk=redirect.pk position=redirect.position|add:"-1" %}">
                      {% csrf_token %}
                      <button aria-label="{% trans 'Move up' %}" title="{% trans 'Move up' %}" class="automation-rule-up">
                        <span>{% trans 'Move up' %}</span>
                      </button>
                    </form>
                  </li>
                {% endif %}

                {% if not forloop.last %}
                  <li class="automation-rule">
                    <form method="post" action="{% url 'projects_redirects_insert' project_slug=project.slug redirect_pk=redirect.pk position=redirect.position|add:"1" %}">
                      {% csrf_token %}
                      <button aria-label="{% trans 'Move down' %}" title="{% trans 'Move down' %}" class="automation-rule-down">
                        <span>{% trans 'Move down' %}</span>
                      </button>
                    </form>
                  </li>
                {% endif %}

                <li>
                  <a href="{% url 'projects_redirects_edit' project_slug=project.slug redirect_pk=redirect.pk %}">
                    {% trans "Edit" %}
                  </a>
                </li>
              </ul>
            </li>
          {% empty %}
            <li class="module-item">
              <p class="quiet">
                {% trans "No redirects found." %}
              </p>
            </li>
          {% endfor %}
        </ul>
      </div>
    </div>
  </div>
{% endblock %}
